<template>
    <div class="schedule-container">
      <div class="pro-tit">
        <span class="tit"></span>限号时间
      </div>
      <div class="applyer-info" data-type="1">
        <div class="v1">
          开始时间：<span>{{ startTime ? startTime : "请设置开始时间" }}</span>
          <van-icon class="v1-icon" name="clock-o" />
        </div>
      </div>
      <div class="applyer-info" @click="showPopup" data-type="2">
        <div class="v1">
          结束时间：<span>{{ endTime ? endTime : "请设置结束时间" }}</span>
          <van-icon class="v1-icon" name="clock-o" />
        </div>
      </div>
      <div class="pro-tit">
        <span class="tit"></span>限号规则
      </div>
      <div class="week-container mB20">
        <div class="week-item" v-for="(day, index) in weekDays" :key="index">
          <div class="w30">
            <span>{{ day.name }}</span>
          </div>
          <div class="w70 flex week-tap">
            <span class="t1" @click="weekTap(day.key)">{{ day.value ? day.value : '请选择' }}</span>
          </div>
        </div>
      </div>
      <van-checkbox v-model="holiday" shape="square" @change="holidayChange" icon-size="14px">是否自动忽略节假日</van-checkbox>
  
      <!-- 选择时间 -->
      <van-popup v-model="datePickerShow" position="bottom">
        <van-datetime-picker
          type="date"
          v-model="currentDate"
          :formatter="formatter"
          :min-hour="minHour"
          :min-date="minDate"
          @confirm="confirmFn"
          @cancel="onClose"
        ></van-datetime-picker>
      </van-popup>
  
      <!-- 选择号码 -->
      <van-dialog v-model="show" show-cancel-button use-title-slot use-slot custom-class="my-custom-class" confirm-button-color="#333" @confirm="submitDialogTap" @cancel="cancleDialogTap">
        <template #title>
          <div class="title">选择号码</div>
        </template>
        <div class="num-body">
          <van-checkbox-group v-model="dayArr" @change="dayChange">
            <div v-for="(num, index) in numbers" :key="index">
              <van-checkbox :name="num" shape="square" class="box-item">{{ num }}</van-checkbox>
            </div>
          </van-checkbox-group>
        </div>
      </van-dialog>
  
      <div class="flex">
        <button class="submit-btn mT30 w45 del" @click="deleteTap" v-if="id && state != 2">删除</button>
        <button class="submit-btn mT30" :class="{ 'w45': id && state != 2 }" @click="submitTap">确定</button>
      </div>
    </div>
  </template>
  
  <script>
  import { Checkbox, CheckboxGroup, DatetimePicker, Popup, Dialog, Icon } from 'vant';
  import 'vant/lib/index.css';
  
  export default {
    components: {
      'van-checkbox': Checkbox,
      'van-checkbox-group': CheckboxGroup,
      'van-datetime-picker': DatetimePicker,
      'van-popup': Popup,
      'van-dialog': Dialog,
      'van-icon': Icon
    },
    data() {
      return {
        startTime: '',
        endTime: '',
        holiday: false,
        datePickerShow: false,
        currentDate: new Date(),
        minHour: 0,
        minDate: new Date(),
        show: false,
        dayArr: [],
        id: null,
        state: null,
        weekDays: [
          { name: '星期一', key: 'one', value: '' },
          { name: '星期二', key: 'two', value: '' },
          { name: '星期三', key: 'three', value: '' },
          { name: '星期四', key: 'four', value: '' },
          { name: '星期五', key: 'five', value: '' },
          { name: '星期六', key: 'six', value: '' },
          { name: '星期日', key: 'seven', value: '' }
        ],
        numbers: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
      };
    },
    methods: {
      showPopup() {
        this.datePickerShow = true;
      },
      onClose() {
        this.datePickerShow = false;
      },
      confirmFn(value) {
        this.currentDate = value;
        this.onClose();
      },
      weekTap(day) {
        // Handle week tap
      },
      holidayChange(value) {
        this.holiday = value;
      },
      dayChange(value) {
        this.dayArr = value;
      },
      submitDialogTap() {
        this.show = false;
      },
      cancleDialogTap() {
        this.show = false;
      },
      deleteTap() {
        // Handle delete
      },
      submitTap() {
        // Handle submit
      }
    }
  };
  </script>
  
  <style scoped>
  .schedule-container {
    background-color: #f5f5f5;
    padding: 20px;
    min-height: 100%;
    font-size: 14px;
    text-align: left;
  }
  
  .pro-tit {
    padding-left: 20px;
    height: 40px;
    line-height: 40px;
    font-size: 18px;
    font-family: Source Han Sans CN;
    font-weight: bold;
    color: #333333;
    margin: 0 0 10px;
    margin: 15px 0;
  }
  
  .tit {
    margin-right: 10px;
    display: inline-block;
    vertical-align: middle;
    width: 9px;
    height: 38px;
    background: #3669F8;
    border-radius: 2px;
    margin-right: 17px;
  }
  
  .mT30 {
    margin-top: 30px;
  }
  
  .mB40 {
    margin-bottom: 40px;
  }
  
  .van-checkbox__label {
    font-size: 14px;
    padding-left: 10px !important;
  }
  
  .applyer-info {
    height: auto;
    padding: 10px;
    background: #FFFFFF;
    border: 1px solid #DDDDDD;
    border-radius: 12px;
    margin-bottom: 15px;
  }
  
  .v1 {
    padding: 0 13px;
    font-size: 16px;
    height: 36px;
    line-height: 36px;
    display: flex;
    justify-content: space-between;
  }
  
  .v1 span {
    font-weight: normal;
    color: #666666;
    font-size: 16px;
    /* width: 72%; */
    display: inline-block;
  }
  .v1 .v1-icon {
    margin-top: 8px;
  }
  
  .v1:nth-last-of-type(1) {
    border: 0;
  }
  
  .week-container {
    border-radius: 12px;
    border: 1px solid #DDDDDD;
    background: #fff;
  }
  
  .week-item {
    height: 50px;
    line-height: 50px;
    border-bottom: 1px solid #DDDDDD;
    font-size: 14px;
    display: flex;
  }
  
  .week-item:nth-last-child(1) {
    border: 0;
  }
  
  .w30 {
    width: 30%;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid #DDDDDD;
  }
  
  .w70 {
    width: 70%;
    text-align: center;
  }
  
  .week-item .t1 {
    width: 80%;
    height: 26px;
    line-height: 26px;
    font-size: 14px;
    display: block;
    background: #FAFCFE;
    border: 1px solid #93B4D5;
    border-radius: 5px;
    color: #B2C7DD;
  }
  
  /* 弹窗 */
  .van-dialog__header {
    padding-top: 0 !important;
  }
  
  .van-dialog__button {
    flex: unset;
    width: 50%;
  }
  
  .van-dialog__cancel,
  .van-dialog__confirm {
    border: 1px !important;
  }
  
  .van-dialog__button:nth-child(1) .van-button--default {
    border-right: 0 !important;
  }
  
  .van-button {
    width: 100% !important;
  }
  
  .title {
    font-size: 16px;
    color: #333333;
    height: 85px;
    line-height: 85px;
    background: #F0F4FF;
    border-radius: 18px;
  }
  
  .box-item {
    display: inline-block;
    width: 33%;
  }
  
  .num-body .van-checkbox {
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 20px !important;
  }
  
  .num-body .van-checkbox__label {
    width: 50%;
    text-align: center;
  }
  
  .num-body {
    width: 80%;
    margin: 40px auto;
  }
  .flex {
    display: flex;
  }
  .align {
    align-items: center;
  }
  .week-tap {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  </style>